import { NGXLogger } from 'ngx-logger';
import { Injectable } from '@angular/core';

// import {NgForage, Driver, NgForageCache, NgForageConfig, CachedItem} from 'ngforage';
import { DB_NAME } from '../entity/TT';
import { PainterEvent } from '../entity/ToolItem';



@Injectable({
  providedIn: 'root'
})
export class OfflineService {

  constructor(
    private log: NGXLogger,
    // private readonly ngf: NgForage,
    // private readonly cache: NgForageCache
  ) {
      this.log.debug('OfflineService ...');

    }

  init() {

  }

  restoringDraw(name: string, cb: (a: PainterEvent) => void) {
    // this.ngf.name = DB_NAME.DRAW.toString();
    // this.ngf.storeName = name;
    //
    // this.log.debug('restoringDraw', this.ngf.name, this.ngf.storeName);
    //
    // this.ngf.keys().then((keys: string[]) => {
    //   keys.forEach(k => {
    //     this.getItem(k).then(cb);
    //   });
    // });

  }

  usingDraw(name: string, reset: boolean = false) {

    // this.ngf.name = DB_NAME.DRAW.toString();
    // this.ngf.storeName = name;
    //
    // this.log.debug('OfflineService.init ...', name, reset);
    //
    // if (reset) {
    //   // delete all stores
    //   this.ngf.length().then(len => {
    //     this.log.debug('clear length:', len);
    //     this.ngf.clear();
    //   });
    // }
  }

  public setDrawItem<T = any>(name: string, key: string, o: T):
    // Promise<T>
  void
  {
    // this.ngf.name = DB_NAME.DRAW.toString();
    // this.ngf.storeName = name;
    // return this.ngf.setItem(key, o);


  }

  // public getItem<T = any>(key: string): Promise<T> {
  //   // return this.ngf.getItem<T>(key);
  // }
  //
  // public getCachedItem<T = any>(key: string): Promise<T | null> {
  //   // return this.cache.getCached<T>(key)
  //   //   .then((r: CachedItem<T>) => {
  //   //     if (!r.hasData || r.expired) {
  //   //       return null;
  //   //     }
  //   //     return r.data;
  //   //   });
  // }

  public getItem<T = any>(key: string): void {
    // return this.ngf.getItem<T>(key);
  }

  public getCachedItem<T = any>(key: string): void {
    // return this.cache.getCached<T>(key)
    //   .then((r: CachedItem<T>) => {
    //     if (!r.hasData || r.expired) {
    //       return null;
    //     }
    //     return r.data;
    //   });
  }


}
